﻿/**
 * 字号插件
 */
(function(E){

var fontSizeList= {
		12 : 3,
		14 : 4,
		18 : 5,
		24 : 6,
		36 : 7
	};

E.plugin("FontSize", {
	menuTitle:'更多字号',
	style: '.jqe-plugin-fontsize a{text-decoration:none;color:#333333;display:block;padding:2px;border:1px solid #eeeeee;background-color:#eeeeee;_float:left;_width:127px;padding-left:25px;}\n'
		+'.jqe-plugin-fontsize a:hover{background-color:#ecf1f7;border:1px solid #aecff7;}\n'
		+'.jqe-plugin-fontsize a.jqe-panel-a-hover{background-color:#ecf1f7;border:1px solid #aecff7;}\n'
		+'#panel_FontSize .jqe-panel-body{padding:2px;}\n',
	
	isNeedTitle:0,
	// 插件图标设置
	icon: {
		width: 40,
		text: '字 号'
	},
	config: {
		// 面板宽度
		width: 160,
		HEIGHT: 160
	},
	
	selectedSize: {},
	
	init: function( self ){
		var html = [];
		for(var i in fontSizeList){
			lineHeight = i>22 ? i: 22;
			html.push('<a href="jqe:FontSize('+i+')" style="font-size:'+i+'px;line-height:'+lineHeight+'px" size="'+fontSizeList[i]+'">'+i+'px</a>');
		}
		self.cache['html'] = '<div class="jqe-plugin-fontsize">'+html.join('')+'</div>';
	},
	
	/**
	 * 设置字号
	 */
	set: function( Panel, self ){
		var size = self.selectedSize[E.eid];
		
		if( !size ){
			size = 4;
		}
		
		self.setFontSize( size );
		self.hide();
		return 1;
	},
	
	
	menu: function( Panel, self ){
		// 设置面板
		Panel.set( self );
		return 1;
	},
	
	/**
	 * 
	 */
	action: function( target, panel, self ){
		var eid = E.eid, name = self.name, 
			size = target.closest('[size]').attr('size'),
			text = target.text();
		if( size ){
			E.log('run', 'FontSize='+size);
			self.selectedSize[eid] = size;
			self.setFontSize( size );
			self.hide();
			
			$('#'+eid+'-'+name).find('span.jqe-icon').text( text );
		}
		return false;
	},
	
	//设置字号
	setFontSize: function( value ){
		var self = this, name = self.name;
		E.execCommand(name, false, value);
	}
});

})(jQEditor);